package com.ht.modules.system.online.codegenerate.generate.util;

import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class GetAllFilesUtil {
    public static List<String> a = new ArrayList<>();
    public static List<String> b = new ArrayList<>();

    public static List<File> getAllFiles(File file) throws IOException {
        List<File> files = new ArrayList<>();
        getAllFiles(file, files);
        files.sort(Comparator.comparing(File::getAbsolutePath));
        return files;
    }

    public static void getAllFiles(File directoryFiles, List<File> files) throws IOException {
        if (!directoryFiles.isHidden() && directoryFiles.isDirectory()) {
            File[] var2 = directoryFiles.listFiles();
            if (var2 == null) {
                throw new IOException("Failed to list contents of " + directoryFiles);
            }
            for (File file : var2) {
                getAllFiles(file, files);
            }
        } else if (!e(directoryFiles) && !d(directoryFiles)) {
            files.add(directoryFiles);
        }
    }

    public static String a(File var0, File var1) {
        return var1.getAbsolutePath().substring(var0.getAbsolutePath().length() + 5);
    }

    public static boolean b(File var0) {
        return !var0.isDirectory() && a(var0.getName());
    }

    public static boolean a(String var0) {
        return !StringUtils.isBlank(b(var0));
    }

    public static String b(String var0) {
        if (var0 == null) {
            return null;
        } else {
            int var1 = var0.indexOf(".");
            return var1 == -1 ? "" : var0.substring(var1 + 1);
        }
    }

    public static File c(String var0) {
        if (var0 == null) {
            throw new IllegalArgumentException("file must be not null");
        } else {
            File var1 = new File(var0);
            c(var1);
            return var1;
        }
    }

    public static void c(File var0) {
        if (var0.getParentFile() != null) {
           var0.getParentFile().mkdirs();
        }
    }

    private static boolean d(File var0) {
        for (String s : a) {
            if (var0.getName().equals(s)) {
                return true;
            }
        }
        return false;
    }

    private static boolean e(File var0) {
        for (String s : b) {
            if (var0.getName().endsWith(s)) {
                return true;
            }
        }
        return false;
    }

    static {
        a.add(".svn");
        a.add("CVS");
        a.add(".cvsignore");
        a.add(".copyarea.db");
        a.add("SCCS");
        a.add("vssver.scc");
        a.add(".DS_Store");
        a.add(".git");
        a.add(".gitignore");
        b.add(".ftl");
    }
}
